{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# QSVM multiclass classification\n",
    "\n",
    "A [multiclass extension](https://qiskit.org/documentation/apidoc/qiskit.aqua.components.multiclass_extensions.html) works in conjunction with an underlying binary (two class) classifier to provide classification where the number of classes is greater than two.\n",
    "\n",
    "Currently the following multiclass extensions are supported:\n",
    "\n",
    "* OneAgainstRest\n",
    "* AllPairs\n",
    "* ErrorCorrectingCode\n",
    "\n",
    "These use different techniques to group the data from the binary classification to achieve the final multiclass classification."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "from qiskit import BasicAer\n",
    "from qiskit.circuit.library import ZZFeatureMap\n",
    "from qiskit.aqua import QuantumInstance, aqua_globals\n",
    "from qiskit.aqua.algorithms import QSVM\n",
    "from qiskit.aqua.components.multiclass_extensions import AllPairs\n",
    "from qiskit.aqua.utils.dataset_helper import get_feature_dimension"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We want a dataset with more than two classes, so here we choose the `Wine` dataset that has 3 classes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "tags": [
     "nbsphinx-thumbnail"
    ]
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAEICAYAAABbOlNNAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3Xu4XHV97/H3x5CQGNskQA5sEi5BUxE1DXRLPeKpCBioHE2qCNFag0JTWi2pfUoN5RQjSk21LULrU6WKxNoKMSqGs+sTLkG8gbCBGAk2EjZySAgQgSCXEEj4nj/Wb8Kaydz2nuue/Xk9zzx75rfWmvnutZP1nd9l/X6K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tzZd1yDtvKiSEnIk6qtE3SI5L6ImJrunA9WuWtTge+HREv5N678G15p6SvAH/VifgiYkv6OSTpe8DRwDfJqqj7pG/FM4EtnYhP0m8CA8AFqepceO+Gz18ZW4BDcq/L/d6FfTZL2geYAjxW57HtiA9JJ5El37dExM5CeYW/dbMvajVjjIjHci+/RNbfVDj2+JJjv9fu+HIWAh/OF7TpHFZTKf6Wnjs3JdVvNVDo+V8EfKfKvnu1U6aLYaE9fwFQdhRCK+OTNK3QBCPpAOA44J7IerNuIusXqXh8G+KbAHybrE11Vcm2Vpy/24HZykZkTSC7MJSOPMnHfRqwNp2v1cBCZaOWZgGzgduaENOw4pN0NPBF4J0R8WiuvOzfusnx1RtjX+7lO4Gfp+drgHkp1mnAPIpr2W2JL8V4JFkn7i25snadw2pWAx9Io5PeCDyZviS19ty1sse9lx5k7co3AvcCNwD7pfJ+4Eu5/Q4ny+YvKzl+LfAzsgva14BXtDs+4E0php+mn2fljj+C7MK2CfgGsG8H4ns/8AKwLveY28rzRzbq4xdk3wIvSGUXkV1oASam87EpnZ8jcsdekI7bCPx+i/7d1YrvBuCR3PlaXetv3YEYPw1sSLHcBByZO/ZD6dxuAj7YifjS62XA8pLjWn4Oyb5Abk3/7jeT9ROdA5yTtgv4fIr9Z0B/O86dp8QwM7MibkoyM7MiTgxmZlbEicHMzIo4MZiZWREnBjMzK+LEYGZmRZwYzMysyP8HpR9CCs3X+O0AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fe260468470>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from qiskit.ml.datasets import wine\n",
    "\n",
    "n = 2  # dimension of each data point\n",
    "sample_Total, training_input, test_input, class_labels = wine(training_size=24,\n",
    "                                                              test_size=6, n=n, plot_data=True)\n",
    "temp = [test_input[k] for k in test_input]\n",
    "total_array = np.concatenate(temp)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To used a multiclass extension an instance thereof simply needs to be supplied, on the QSVM creation, using the `multiclass_extension` parameter. Although `AllPairs()` is used in the example below, the following multiclass extensions would also work:\n",
    "\n",
    "    OneAgainstRest()\n",
    "    ErrorCorrectingCode(code_size=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "testing_accuracy : 1.0\n",
      "test_success_ratio : 1.0\n",
      "predicted_labels : [0 1 2 2 2 2]\n",
      "predicted_classes : ['A', 'B', 'C', 'C', 'C', 'C']\n"
     ]
    }
   ],
   "source": [
    "aqua_globals.random_seed = 10598\n",
    "\n",
    "backend = BasicAer.get_backend('qasm_simulator')\n",
    "feature_map = ZZFeatureMap(feature_dimension=get_feature_dimension(training_input),\n",
    "                           reps=2, entanglement='linear')\n",
    "svm = QSVM(feature_map, training_input, test_input, total_array,\n",
    "           multiclass_extension=AllPairs())\n",
    "quantum_instance = QuantumInstance(backend, shots=1024,\n",
    "                                   seed_simulator=aqua_globals.random_seed,\n",
    "                                   seed_transpiler=aqua_globals.random_seed)\n",
    "\n",
    "result = svm.run(quantum_instance)\n",
    "for k,v in result.items():\n",
    "    print(f'{k} : {v}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-08-22T01:49:36.816822Z",
     "start_time": "2019-08-22T01:49:36.806994Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<h3>Version Information</h3><table><tr><th>Qiskit Software</th><th>Version</th></tr><tr><td>Qiskit</td><td>0.23.0</td></tr><tr><td>Terra</td><td>0.16.0</td></tr><tr><td>Aer</td><td>0.7.0</td></tr><tr><td>Ignis</td><td>0.5.0</td></tr><tr><td>Aqua</td><td>0.8.0</td></tr><tr><td>IBM Q Provider</td><td>0.11.0</td></tr><tr><th>System information</th></tr><tr><td>Python</td><td>3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:09:58) \n",
       "[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]</td></tr><tr><td>OS</td><td>Linux</td></tr><tr><td>CPUs</td><td>1</td></tr><tr><td>Memory (Gb)</td><td>5.827335357666016</td></tr><tr><td colspan='2'>Thu Nov 12 17:37:28 2020 EST</td></tr></table>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div style='width: 100%; background-color:#d5d9e0;padding-left: 10px; padding-bottom: 10px; padding-right: 10px; padding-top: 5px'><h3>This code is a part of Qiskit</h3><p>&copy; Copyright IBM 2017, 2020.</p><p>This code is licensed under the Apache License, Version 2.0. You may<br>obtain a copy of this license in the LICENSE.txt file in the root directory<br> of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.<p>Any modifications or derivative works of this code must retain this<br>copyright notice, and modified files need to carry a notice indicating<br>that they have been altered from the originals.</p></div>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import qiskit.tools.jupyter\n",
    "%qiskit_version_table\n",
    "%qiskit_copyright"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
